﻿using System;
using System.Collections.Generic;
using System.Text;

namespace XAJH
{
    /// <summary>
    /// 游戏类
    /// </summary>
    public class Game
    {
        /// <summary>
        /// 获取窗口句柄
        /// </summary>
        /// <param name="lpClassName"></param>
        /// <param name="lpWindowName"></param>
        /// <returns></returns>
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindowA")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        /// <summary>
        /// 获取窗口句柄
        /// </summary>
        /// <returns></returns>
        public static IntPtr GetGameWindow()
        {
            return FindWindow("111", null);
        }

        /// <summary>
        /// 键盘单击
        /// </summary>
        /// <param name="key"> 键盘 </param>
        /// <param name="delay"> 延时 </param>
        public static void KeyPress(System.Windows.Forms.Keys key, IntPtr hWnd = default (IntPtr), int delay = 0)
        {
            if (FormHelper.IsWindowEnabled(hWnd))
                KeyboardHelper.KeyPress(key, delay);
        }

        /// <summary>
        /// 鼠标单击
        /// </summary>
        /// <param name="hWnd"> 窗口 </param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public static void MouseClick(IntPtr hWnd = default (IntPtr), int? x = null, int? y = null)
        {
            if (FormHelper.IsWindowEnabled(hWnd))
                MouseHelper.LeftClick(hWnd, x, y);
        }

        /// <summary>
        /// 鼠标移动
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public static void MoveTo(IntPtr hWnd, int x, int y)
        {
            if (FormHelper.IsWindowEnabled(hWnd))
                MouseHelper.MoveTo(hWnd, x, y);
        }
    }
}
